<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"><title>实践一下--工作常用小技巧 | Celts</title><meta name="author" content="PaulGeorge"><meta name="copyright" content="PaulGeorge"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="工作常用小技巧 ( 10条 &#x2F; 篇 )  本篇着重介绍一下工作常用小技巧      写在前面 工作中经常会用到的小技巧，来让我们一起来看看？">
<meta property="og:type" content="article">
<meta property="og:title" content="实践一下--工作常用小技巧">
<meta property="og:url" content="https://curry3035.gitee.io/posts/51404/index.html">
<meta property="og:site_name" content="Celts">
<meta property="og:description" content="工作常用小技巧 ( 10条 &#x2F; 篇 )  本篇着重介绍一下工作常用小技巧      写在前面 工作中经常会用到的小技巧，来让我们一起来看看？">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://curry3035.gitee.io/img/avatar.jpg">
<meta property="article:published_time" content="2021-03-30T01:00:00.000Z">
<meta property="article:modified_time" content="2022-05-26T18:16:36.204Z">
<meta property="article:author" content="PaulGeorge">
<meta property="article:tag" content="小技巧">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://curry3035.gitee.io/img/avatar.jpg"><link rel="shortcut icon" href="/img/ic.ico"><link rel="canonical" href="https://curry3035.gitee.io/posts/51404/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":false,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: true
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50,"languages":{"author":"作者: PaulGeorge","link":"链接: ","source":"来源: Celts","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#1f1f1f","position":"top-right"},
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '实践一下--工作常用小技巧',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-05-27 02:16:36'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/background.css"><link rel="stylesheet" href="/css/my.css"><meta name="generator" content="Hexo 5.4.2"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/avatar.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">97</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">64</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/photos/"><i class="fa-fw fa fa-camera-retro"></i><span> 图库</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://gcore.jsdelivr.net/gh/PaulGeorge123/cloudimg@img/mig2023/background05.jpg')"><nav id="nav"><span id="blog-info"><a href="/" title="Celts"><span class="site-name">Celts</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/photos/"><i class="fa-fw fa fa-camera-retro"></i><span> 图库</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">实践一下--工作常用小技巧</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-03-30T01:00:00.000Z" title="发表于 2021-03-30 09:00:00">2021-03-30</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-05-26T18:16:36.204Z" title="更新于 2022-05-27 02:16:36">2022-05-27</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%B7%A5%E4%BD%9C/">工作</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2.2k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>9分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="实践一下--工作常用小技巧"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><blockquote>
<p>工作常用小技巧 ( 10条 / 篇 )</p>
</blockquote>
<p><strong>本篇着重介绍一下工作常用小技巧</strong></p>
<hr>
<img src="https://gcore.jsdelivr.net/gh/PaulGeorge123/cloudimg@master/img/all/Snipaste_2021-12-02_10-21-06.png" style="zoom:80%;" />



<p><strong>写在前面</strong></p>
<p><font color=#008000>工作中经常会用到的小技巧，来让我们一起来看看？</font></p>
<span id="more"></span>



<h3 id="Java-正确-URL-解码方式"><a href="#Java-正确-URL-解码方式" class="headerlink" title="Java 正确 URL 解码方式"></a>Java 正确 URL 解码方式</h3><p> 我们经常会遇到乱码的问题，那么首先可能想到的就是使用过滤器来处理，但是使用过滤器的话就会过滤所有请求，有的请求是不需要过滤的，所以如果需要过滤的请求不多的情况下，我们可以对请求进行特别处理。</p>
<h4 id="urlEncoder-和-urlDecode"><a href="#urlEncoder-和-urlDecode" class="headerlink" title="urlEncoder 和 urlDecode"></a>urlEncoder 和 urlDecode</h4><p>使用指定的编码机制将字符串转换为 application/x-www-form-urlencoded 格式 </p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line">URLEncoder.encode(String s, String enc) [enc --&gt; <span class="string">&quot;utf-8&quot;</span>]</span><br></pre></td></tr></table></figure>

<p>使用指定的编码机制对 application/x-www-form-urlencoded 字符串解码。 </p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line">URLDecoder.decode(String s, String enc) [enc --&gt; <span class="string">&quot;utf-8&quot;</span>]</span><br></pre></td></tr></table></figure>

<hr>
<h3 id="Mybatis-中查询时间段内数据"><a href="#Mybatis-中查询时间段内数据" class="headerlink" title="Mybatis 中查询时间段内数据"></a>Mybatis 中查询时间段内数据</h3><h4 id="数据库使用-Date-类型"><a href="#数据库使用-Date-类型" class="headerlink" title="数据库使用 Date 类型"></a>数据库使用 Date 类型</h4><figure class="highlight xml"><table><tr><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">if</span> <span class="attr">test</span>=<span class="string">&quot;minCreateTime != null and  minCreateTime != &#x27;&#x27;&quot;</span>&gt;</span></span><br><span class="line">  &lt;![CDATA[ and g.create_time &gt;= to_date(#&#123;minCreateTime,jdbcType=DATE&#125;,&#x27;yyyy-MM-dd hh24:mi:ss&#x27;)]]&gt;</span><br><span class="line"><span class="tag">&lt;/<span class="name">if</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">if</span> <span class="attr">test</span>=<span class="string">&quot;maxCreateTime != null and  maxCreateTime != &#x27;&#x27;&quot;</span>&gt;</span></span><br><span class="line">  &lt;![CDATA[ and g.create_time &lt;= to_date(#&#123;maxCreateTime,jdbcType=DATE&#125;,&#x27;yyyy-MM-dd hh24:mi:ss&#x27;)]]&gt;</span><br><span class="line"><span class="tag">&lt;/<span class="name">if</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h4 id="数据库使用字符串类型"><a href="#数据库使用字符串类型" class="headerlink" title="数据库使用字符串类型"></a>数据库使用字符串类型</h4><figure class="highlight xml"><table><tr><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">if</span> <span class="attr">test</span>=<span class="string">&quot;createTime != null&quot;</span>&gt;</span></span><br><span class="line">    AND CREATE_TIME = CONCAT(CONCAT(&#x27;%&#x27;, #&#123;createTime,jdbcType=DATE&#125;), &#x27;%&#x27;)</span><br><span class="line"><span class="tag">&lt;/<span class="name">if</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">if</span> <span class="attr">test</span>=<span class="string">&quot;updateTime != null&quot;</span>&gt;</span></span><br><span class="line">    AND UPDATE_TIME = CONCAT(CONCAT(&#x27;%&#x27;, #&#123;updateTime,jdbcType=DATE&#125;), &#x27;%&#x27;)</span><br><span class="line"><span class="tag">&lt;/<span class="name">if</span>&gt;</span></span><br></pre></td></tr></table></figure>



<hr>
<h3 id="Java-Date-与-String-的相互转换"><a href="#Java-Date-与-String-的相互转换" class="headerlink" title="Java Date 与 String 的相互转换"></a>Java Date 与 String 的相互转换</h3><h4 id="Java-String-转-Date"><a href="#Java-String-转-Date" class="headerlink" title="Java String 转 Date"></a>Java String 转 Date</h4><p>接口之间数据的传输都是字符串，现在需要把数据存储在数据库中，定义对象的时候将日期定义为了Date，所以不得不把String转为Date对象。</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">// 获取当前时间（格式：yyyy-MM-dd HH:mm:ss）</span></span><br><span class="line"><span class="type">String</span> <span class="variable">time</span> <span class="operator">=</span> <span class="string">&quot;2021-01-01 10:10:10&quot;</span>;</span><br><span class="line"><span class="comment">// 设置日期格式</span></span><br><span class="line"><span class="type">SimpleDateFormat</span> <span class="variable">simpleDateFormat</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">SimpleDateFormat</span>(<span class="string">&quot;yyyy-MM-dd HH:mm:ss&quot;</span>);</span><br><span class="line"><span class="comment">// 将字符串解析成日期</span></span><br><span class="line"><span class="type">Date</span> <span class="variable">date</span> <span class="operator">=</span> simpleDateFormat.parse(time);</span><br></pre></td></tr></table></figure>

<h4 id="Java-Date-转-String"><a href="#Java-Date-转-String" class="headerlink" title="Java Date 转 String"></a>Java Date 转 String</h4><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">// 获取当前时间（返回格式：yyyy-MM-dd HH:mm:ss）</span></span><br><span class="line"><span class="type">Date</span> <span class="variable">date</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Date</span>();</span><br><span class="line"><span class="comment">// 设置日期格式</span></span><br><span class="line"><span class="type">SimpleDateFormat</span> <span class="variable">df</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">SimpleDateFormat</span>(<span class="string">&quot;yyyy-MM-dd HH:mm:ss&quot;</span>);</span><br><span class="line"><span class="comment">// new Date()为获取当前系统时间</span></span><br><span class="line"><span class="type">String</span> <span class="variable">time</span> <span class="operator">=</span> df.format(date);</span><br></pre></td></tr></table></figure>

<h4 id="计算某天-n-天之后的日期"><a href="#计算某天-n-天之后的日期" class="headerlink" title="计算某天 n 天之后的日期"></a>计算某天 n 天之后的日期</h4><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">static</span> String <span class="title function_">getBeforeAfterDateDay</span><span class="params">(String time, <span class="type">int</span> day)</span> <span class="keyword">throws</span> Exception&#123;</span><br><span class="line">    <span class="type">SimpleDateFormat</span> <span class="variable">sdf</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">SimpleDateFormat</span>(<span class="string">&quot;yyyy-MM-dd&quot;</span>);</span><br><span class="line">    <span class="type">Date</span> <span class="variable">date</span> <span class="operator">=</span> sdf.parse(time);</span><br><span class="line">    <span class="type">Calendar</span> <span class="variable">cal</span> <span class="operator">=</span> Calendar.getInstance();</span><br><span class="line">    cal.setTime(date);</span><br><span class="line"></span><br><span class="line">    <span class="type">int</span> <span class="variable">Year</span> <span class="operator">=</span> cal.get(Calendar.YEAR);</span><br><span class="line">    <span class="type">int</span> <span class="variable">Month</span> <span class="operator">=</span> cal.get(Calendar.MONTH);</span><br><span class="line">    <span class="type">int</span> <span class="variable">Day</span> <span class="operator">=</span> cal.get(Calendar.DAY_OF_MONTH);</span><br><span class="line"></span><br><span class="line">    <span class="type">int</span> <span class="variable">NewDay</span> <span class="operator">=</span> Day + day;</span><br><span class="line"></span><br><span class="line">    cal.set(Calendar.YEAR, Year);</span><br><span class="line">    cal.set(Calendar.MONTH, Month);</span><br><span class="line">    cal.set(Calendar.DAY_OF_MONTH, NewDay);</span><br><span class="line"></span><br><span class="line">    <span class="type">String</span> <span class="variable">newTime</span> <span class="operator">=</span> sdf.format(<span class="keyword">new</span> <span class="title class_">Date</span>(cal.getTimeInMillis()));</span><br><span class="line">    <span class="keyword">return</span> newTime;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<hr>
<h3 id="Git-命令"><a href="#Git-命令" class="headerlink" title="Git 命令"></a>Git 命令</h3><h4 id="将最新的-master-分支代码更新到其他分支"><a href="#将最新的-master-分支代码更新到其他分支" class="headerlink" title="将最新的 master 分支代码更新到其他分支"></a>将最新的 master 分支代码更新到其他分支</h4><ol>
<li>将分支切换到master</li>
</ol>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git checkout master</span><br></pre></td></tr></table></figure>

<ol start="2">
<li>将代码pull到本地</li>
</ol>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git pull</span><br></pre></td></tr></table></figure>

<ol start="3">
<li>修改冲突</li>
</ol>
<ol start="4">
<li>提交代码到本地</li>
</ol>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git add .</span><br><span class="line">git commit -m <span class="string">&quot;msg&quot;</span></span><br></pre></td></tr></table></figure>

<ol start="5">
<li>切换到要更新的分支上</li>
</ol>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git checkout 分支名</span><br></pre></td></tr></table></figure>

<ol start="6">
<li>merge</li>
</ol>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git merge master</span><br></pre></td></tr></table></figure>

<ol start="7">
<li>将本地跟新好的内容push到分支</li>
</ol>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git push</span><br></pre></td></tr></table></figure>

<hr>
<h3 id="优雅的代码总结"><a href="#优雅的代码总结" class="headerlink" title="优雅的代码总结"></a>优雅的代码总结</h3><h4 id="1-static-成员变量"><a href="#1-static-成员变量" class="headerlink" title="1.static 成员变量"></a>1.static 成员变量</h4><p><font color=#FF8C00>“类名 . 静态变量名”</font></p>
<p>静态成员变量是属于类的，也就是说，该成员变量并不属于某个对象，即使有多个该类的对象实例，静态成员变量也只有一个；</p>
<p>只要静态成员变量所在的类被加载，这个静态成员变量就会被分配内存空间。因此在引用该静态成员变量时，通常不需要生成该类的对象，而是通过类名直接引用；</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Student</span> &#123;</span><br><span class="line">    <span class="comment">// 静态成员变量</span></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> String schoolName;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> <span class="type">int</span> nums;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// 非静态成员变量</span></span><br><span class="line">    <span class="keyword">private</span> String name;</span><br><span class="line">    <span class="keyword">private</span> <span class="type">int</span> age;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="2-static-成员方法"><a href="#2-static-成员方法" class="headerlink" title="2.static 成员方法"></a>2.static 成员方法</h4><p>静态成员方法是类方法，它属于类本身而不属于某个对象；因此静态成员方法不需要创建对象就可以被调用，而非静态成员方法则需要通过对象来调用；</p>
<p><font color=#FF8C00>在静态成员方法中不能使用 this、super 关键字，也不能调用非静态成员方法，同时不能引用非静态成员变量</font></p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Student</span> &#123;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> String SchoolName;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> <span class="type">int</span> nums;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// 静态成员方法</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> String <span class="title function_">getSchoolName</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> Student.SchoolName;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="3-static-代码块"><a href="#3-static-代码块" class="headerlink" title="3.static 代码块"></a>3.static 代码块</h4><p>static 代码块又称为静态代码块，或静态初始化器。它是在类中独立于成员函数的代码块；</p>
<p>static 代码块不需要程序主动调用，在JVM加载类时系统会执行 static 代码块，因此在static 代码块中可以做一些类成员变量的初始化工作；</p>
<p>如果一个类中有多个 static 代码块，JVM将会按顺序依次执行。需要注意的是，所有的static 代码块只能在JVM加载类时被执行一次；</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Student</span> &#123;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> String SchoolName;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> <span class="type">int</span> nums;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// 静态代码块</span></span><br><span class="line">    <span class="keyword">static</span> &#123;</span><br><span class="line">        Student.SchoolName = <span class="string">&quot;清华大学&quot;</span>;</span><br><span class="line">        Student.nums = <span class="number">0</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="4-static-内部类"><a href="#4-static-内部类" class="headerlink" title="4.static 内部类"></a>4.static 内部类</h4><p>静态成员内部类的特点主要是它本身是类相关的内部类，所以它可以不依赖于外部类实例而被实例化</p>
<p>静态内部类不能访问其外部类的实例成员（包括普通的成员变量和方法），只能访问外部类的类成员（包括静态成员变量和静态方法）;</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Student</span> &#123;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> String SchoolName;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> <span class="type">int</span> nums;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// 静态内部类</span></span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">class</span> <span class="title class_">test</span>&#123;</span><br><span class="line">        <span class="keyword">public</span> <span class="title function_">test</span><span class="params">()</span> &#123;</span><br><span class="line">            System.out.println(<span class="string">&quot;Hello Word!&quot;</span> );</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<hr>
<h3 id="DeepinCopy-深拷贝"><a href="#DeepinCopy-深拷贝" class="headerlink" title="DeepinCopy 深拷贝"></a>DeepinCopy 深拷贝</h3><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">CpoyUtil</span> &#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> List&lt;Object&gt; <span class="title function_">DeepinCopy</span><span class="params">(List&lt;Object&gt; list)</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> list.stream().map(res -&gt; &#123;</span><br><span class="line">            <span class="type">Object</span> <span class="variable">entity</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Object</span>();</span><br><span class="line">            BeanUtils.copyProperties(res, entity);</span><br><span class="line">            <span class="keyword">return</span> entity;</span><br><span class="line">        &#125;).collect(Collectors.toList());</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>Object 可替换成相应的对象</p>
</blockquote>
<hr>
<h3 id="Sql-中-limit-与-offset连用的区别"><a href="#Sql-中-limit-与-offset连用的区别" class="headerlink" title="Sql 中 limit 与 offset连用的区别"></a>Sql 中 limit 与 offset连用的区别</h3><figure class="highlight sql"><table><tr><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> <span class="keyword">table</span> limit <span class="number">2</span>,<span class="number">1</span>;                </span><br><span class="line"> </span><br><span class="line"><span class="comment">-- 含义是跳过2条取出1条数据，limit后面是从第2条开始读，读取1条信息，即读取第3条数据</span></span><br><span class="line"> </span><br><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> <span class="keyword">table</span> limit <span class="number">2</span> <span class="keyword">offset</span> <span class="number">1</span>;     </span><br><span class="line"> </span><br><span class="line"><span class="comment">-- 含义是从第1条（不包括）数据开始取出2条数据，limit后面跟的是2条数据，offset后面是从第1条开始读取，即读取第2,3条</span></span><br></pre></td></tr></table></figure>

<hr>
<h3 id="Java-对象与-JSON-数据的互相转换"><a href="#Java-对象与-JSON-数据的互相转换" class="headerlink" title="Java 对象与 JSON 数据的互相转换"></a>Java 对象与 JSON 数据的互相转换</h3><p><strong>通过 FastJson（JSON类）解析</strong></p>
<h4 id="将-Java-对象转换为字符串-–-序列化"><a href="#将-Java-对象转换为字符串-–-序列化" class="headerlink" title="将 Java 对象转换为字符串 – (序列化)"></a>将 Java 对象转换为字符串 – (序列化)</h4><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">//将对象转换为字符串</span></span><br><span class="line"><span class="type">Book</span> <span class="variable">book</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Book</span>(<span class="number">1001</span>,<span class="string">&quot;Java&quot;</span>,<span class="string">&quot;Java基础&quot;</span>);</span><br><span class="line"><span class="type">String</span> <span class="variable">jsonString</span> <span class="operator">=</span> JSON.toJSONString(book);</span><br><span class="line">System.out.println(jsonString);</span><br></pre></td></tr></table></figure>

<p>结果：</p>
<figure class="highlight json"><table><tr><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span><span class="attr">&quot;id&quot;</span><span class="punctuation">:</span><span class="number">1001</span><span class="punctuation">,</span><span class="attr">&quot;info&quot;</span><span class="punctuation">:</span><span class="string">&quot;Java基础&quot;</span><span class="punctuation">,</span><span class="attr">&quot;name&quot;</span><span class="punctuation">:</span><span class="string">&quot;Java&quot;</span><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>



<h4 id="将-JSON-格式字符串解析为-Java-对象-–-反序列化"><a href="#将-JSON-格式字符串解析为-Java-对象-–-反序列化" class="headerlink" title="将 JSON 格式字符串解析为 Java 对象 – (反序列化)"></a>将 JSON 格式字符串解析为 Java 对象 – (反序列化)</h4>   <figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">//将JSON字符串转换为Java对象</span></span><br><span class="line"><span class="type">String</span> <span class="variable">bookJson</span> <span class="operator">=</span> <span class="string">&quot;&#123;\&quot;id\&quot;:1001,\&quot;name\&quot;:\&quot;Java\&quot;,\&quot;info\&quot;:\&quot;Java基础\&quot;&#125;&quot;</span>;</span><br><span class="line"><span class="type">Book</span> <span class="variable">book</span> <span class="operator">=</span> JSON.parseObject(bookJson,Book.class);</span><br><span class="line">System.out.println(book);</span><br></pre></td></tr></table></figure>

<p>结果：</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line">Book&#123;id=<span class="number">1001</span>, name=<span class="string">&quot;Java&quot;</span>, info=<span class="string">&quot;Java基础&quot;</span>&#125;</span><br></pre></td></tr></table></figure>



<h4 id="将-Json-转换复杂的-Bean-对象"><a href="#将-Json-转换复杂的-Bean-对象" class="headerlink" title="将 Json 转换复杂的 Bean 对象"></a>将 Json 转换复杂的 Bean 对象</h4><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="type">String</span> <span class="variable">jsonString</span> <span class="operator">=</span> <span class="string">&quot;[&#123;\&quot;id\&quot;:\&quot;1\&quot;,\&quot;name\&quot;:\&quot;Json技术\&quot;&#125;,&#123;\&quot;id\&quot;:\&quot;2\&quot;,\&quot;name\&quot;:\&quot;java技术\&quot;&#125;]&quot;</span>;</span><br><span class="line"><span class="comment">// 将json转换成List</span></span><br><span class="line"><span class="type">List</span> <span class="variable">list</span> <span class="operator">=</span> JSON.parseObject(jsonString, <span class="keyword">new</span> <span class="title class_">TypeReference</span>&lt;ARRAYLIST&gt;()&#123;&#125;);</span><br><span class="line"><span class="comment">// 将json转换成Set</span></span><br><span class="line"><span class="type">Set</span> <span class="variable">set</span> <span class="operator">=</span> JSON.parseObject(jsonString, <span class="keyword">new</span> <span class="title class_">TypeReference</span>&lt;HASHSET&gt;()&#123;&#125;);</span><br></pre></td></tr></table></figure>

<hr>
<h3 id="Gson-和-Fastjson-区别"><a href="#Gson-和-Fastjson-区别" class="headerlink" title="Gson 和 Fastjson 区别"></a>Gson 和 Fastjson 区别</h3><h4 id="Bean-转换-Json：toJson"><a href="#Bean-转换-Json：toJson" class="headerlink" title="Bean 转换 Json：toJson"></a>Bean 转换 Json：toJson</h4><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="type">Gson</span> <span class="variable">gson</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Gson</span>();</span><br><span class="line"><span class="type">String</span> <span class="variable">json</span> <span class="operator">=</span> gson.toJson(obj);</span><br></pre></td></tr></table></figure>



<h4 id="Json-转换-Bean：fromJson"><a href="#Json-转换-Bean：fromJson" class="headerlink" title="Json 转换 Bean：fromJson"></a>Json 转换 Bean：fromJson</h4><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="type">Gson</span> <span class="variable">gson</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Gson</span>();</span><br><span class="line"><span class="type">String</span> <span class="variable">json</span> <span class="operator">=</span> <span class="string">&quot;&#123;\&quot;id\&quot;:\&quot;2\&quot;,\&quot;name\&quot;:\&quot;Json技术\&quot;&#125;&quot;</span>;</span><br><span class="line"><span class="type">Book</span> <span class="variable">book</span> <span class="operator">=</span> gson.fromJson(json, Book.class);</span><br></pre></td></tr></table></figure>



<h4 id="Json-转换复杂的-Bean"><a href="#Json-转换复杂的-Bean" class="headerlink" title="Json 转换复杂的 Bean"></a>Json 转换复杂的 Bean</h4><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">// 将json转换成复杂类型的bean,需要使用TypeToken</span></span><br><span class="line"><span class="type">Gson</span> <span class="variable">gson</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Gson</span>();</span><br><span class="line"><span class="type">String</span> <span class="variable">json</span> <span class="operator">=</span> <span class="string">&quot;[&#123;\&quot;id\&quot;:\&quot;1\&quot;,\&quot;name\&quot;:\&quot;Json技术\&quot;&#125;,&#123;\&quot;id\&quot;:\&quot;2\&quot;,\&quot;name\&quot;:\&quot;java技术\&quot;&#125;]&quot;</span>;</span><br><span class="line"><span class="comment">// 将json转换成List</span></span><br><span class="line"><span class="type">List</span> <span class="variable">list</span> <span class="operator">=</span> gson.fromJson(json, <span class="keyword">new</span> <span class="title class_">TypeToken</span>&lt;List&gt;() &#123;&#125;.getType());</span><br><span class="line"><span class="comment">// 将json转换成Set</span></span><br><span class="line"><span class="type">Set</span> <span class="variable">set</span> <span class="operator">=</span> gson.fromJson(json, <span class="keyword">new</span> <span class="title class_">TypeToken</span>&lt;Set&gt;() &#123;&#125;.getType());</span><br></pre></td></tr></table></figure>



<p><strong>总结</strong></p>
<p>如果<strong>只是功能要求</strong>，没有性能要求，可以<strong>使用 google 的 Gson</strong>，</p>
<p>如果有<strong>性能上面的要求</strong>可以使用 <strong>Gson 将 bean 转换 json 确保数据的正确 (序列化)，使用 FastJson 将 Json 转换 Bean (反序列化)</strong></p>
<hr>
<h3 id="Git忽略文件-gitignore"><a href="#Git忽略文件-gitignore" class="headerlink" title="Git忽略文件.gitignore"></a>Git忽略文件.gitignore</h3><h4 id="常用匹配示例"><a href="#常用匹配示例" class="headerlink" title="常用匹配示例"></a>常用匹配示例</h4><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">bin/: 忽略当前路径下的bin文件夹，该文件夹下的所有内容都会被忽略，不忽略 bin 文件</span><br><span class="line"></span><br><span class="line">/bin: 忽略根目录下的bin文件</span><br><span class="line"></span><br><span class="line">/*.c: 忽略 cat.c，不忽略 build/cat.c</span><br><span class="line"></span><br><span class="line">debug/*.obj: 忽略 debug/io.obj，不忽略 debug/common/io.obj 和 tools/debug/io.obj</span><br><span class="line"></span><br><span class="line">**/foo: 忽略/foo, a/foo, a/b/foo等</span><br><span class="line"></span><br><span class="line">a/**/b: 忽略a/b, a/x/b, a/x/y/b等</span><br><span class="line"></span><br><span class="line">!/bin/run.sh: 不忽略 bin 目录下的 run.sh 文件</span><br><span class="line"></span><br><span class="line">*.log: 忽略所有 .log 文件</span><br><span class="line"></span><br><span class="line">config.php: 忽略当前路径的 config.php 文件</span><br></pre></td></tr></table></figure>



<p>如果想添加一个文件到Git，但发现添加不了，原因是这个文件被 <code>.gitignore</code> 忽略了。</p>
<p>如果你确实想添加该文件，可以用 -f 强制添加到 Git</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">$ git add -f App.class</span><br></pre></td></tr></table></figure>



<p>用 <code>git check-ignore</code> 命令可以检查 哪个 <code>.gitignore</code> 写得有问题</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">$ git check-ignore -v App.class</span><br><span class="line">.gitignore:3:*.class    App.class</span><br></pre></td></tr></table></figure>

<blockquote>
<p>.gitignore 的第3行规则忽略了该文件</p>
</blockquote>
<h4 id="Java-项目中常用的-gitignore-文件"><a href="#Java-项目中常用的-gitignore-文件" class="headerlink" title="Java 项目中常用的 .gitignore 文件"></a>Java 项目中常用的 .gitignore 文件</h4><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line"># Compiled class file</span><br><span class="line">*.class</span><br><span class="line"></span><br><span class="line"># Eclipse</span><br><span class="line">.project</span><br><span class="line">.classpath</span><br><span class="line">.settings/</span><br><span class="line"></span><br><span class="line"># Intellij</span><br><span class="line">*.ipr</span><br><span class="line">*.iml</span><br><span class="line">*.iws</span><br><span class="line">.idea/</span><br><span class="line"></span><br><span class="line"># Maven</span><br><span class="line">target/</span><br><span class="line"></span><br><span class="line"># Gradle</span><br><span class="line">build</span><br><span class="line">.gradle</span><br><span class="line"></span><br><span class="line"># Log file</span><br><span class="line">*.log</span><br><span class="line">log/</span><br><span class="line"></span><br><span class="line"># out</span><br><span class="line">**/out/</span><br><span class="line"></span><br><span class="line"># Mac</span><br><span class="line">.DS_Store</span><br><span class="line"></span><br><span class="line"># others</span><br><span class="line">*.jar</span><br><span class="line">*.war</span><br><span class="line">*.zip</span><br><span class="line">*.tar</span><br><span class="line">*.tar.gz</span><br><span class="line">*.pid</span><br><span class="line">*.orig</span><br><span class="line">temp/</span><br></pre></td></tr></table></figure>



<br/>

<p><strong>未完待续 … …</strong></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://curry3035.gitee.io">PaulGeorge</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://curry3035.gitee.io/posts/51404/">https://curry3035.gitee.io/posts/51404/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://curry3035.gitee.io" target="_blank">Celts</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E5%B0%8F%E6%8A%80%E5%B7%A7/">小技巧</a></div><div class="post_share"><div class="social-share" data-image="/img/avatar.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/posts/32841/" title="实践一下--工作常用小技巧2"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">实践一下--工作常用小技巧2</div></div></a></div><div class="next-post pull-right"><a href="/posts/25888/" title="PageHelper"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">PageHelper</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/posts/32841/" title="实践一下--工作常用小技巧2"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-04-02</div><div class="title">实践一下--工作常用小技巧2</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/avatar.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">PaulGeorge</div><div class="author-info__description">很多事情就像是旅行一样，当你决定要出发的时候，最困难的那部分其实就已经完成了</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">97</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">64</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/PaulGeorge123"><i class="fab fa-github"></i><span>GitHub URL</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/PaulGeorge123" target="_blank" title="Github"><i class="fab fa-github"></i></a></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content is-expand"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#Java-%E6%AD%A3%E7%A1%AE-URL-%E8%A7%A3%E7%A0%81%E6%96%B9%E5%BC%8F"><span class="toc-number">1.</span> <span class="toc-text">Java 正确 URL 解码方式</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#urlEncoder-%E5%92%8C-urlDecode"><span class="toc-number">1.1.</span> <span class="toc-text">urlEncoder 和 urlDecode</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Mybatis-%E4%B8%AD%E6%9F%A5%E8%AF%A2%E6%97%B6%E9%97%B4%E6%AE%B5%E5%86%85%E6%95%B0%E6%8D%AE"><span class="toc-number">2.</span> <span class="toc-text">Mybatis 中查询时间段内数据</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E5%BA%93%E4%BD%BF%E7%94%A8-Date-%E7%B1%BB%E5%9E%8B"><span class="toc-number">2.1.</span> <span class="toc-text">数据库使用 Date 类型</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E5%BA%93%E4%BD%BF%E7%94%A8%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%B1%BB%E5%9E%8B"><span class="toc-number">2.2.</span> <span class="toc-text">数据库使用字符串类型</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Java-Date-%E4%B8%8E-String-%E7%9A%84%E7%9B%B8%E4%BA%92%E8%BD%AC%E6%8D%A2"><span class="toc-number">3.</span> <span class="toc-text">Java Date 与 String 的相互转换</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#Java-String-%E8%BD%AC-Date"><span class="toc-number">3.1.</span> <span class="toc-text">Java String 转 Date</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Java-Date-%E8%BD%AC-String"><span class="toc-number">3.2.</span> <span class="toc-text">Java Date 转 String</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%AE%A1%E7%AE%97%E6%9F%90%E5%A4%A9-n-%E5%A4%A9%E4%B9%8B%E5%90%8E%E7%9A%84%E6%97%A5%E6%9C%9F"><span class="toc-number">3.3.</span> <span class="toc-text">计算某天 n 天之后的日期</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Git-%E5%91%BD%E4%BB%A4"><span class="toc-number">4.</span> <span class="toc-text">Git 命令</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%B0%86%E6%9C%80%E6%96%B0%E7%9A%84-master-%E5%88%86%E6%94%AF%E4%BB%A3%E7%A0%81%E6%9B%B4%E6%96%B0%E5%88%B0%E5%85%B6%E4%BB%96%E5%88%86%E6%94%AF"><span class="toc-number">4.1.</span> <span class="toc-text">将最新的 master 分支代码更新到其他分支</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BC%98%E9%9B%85%E7%9A%84%E4%BB%A3%E7%A0%81%E6%80%BB%E7%BB%93"><span class="toc-number">5.</span> <span class="toc-text">优雅的代码总结</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-static-%E6%88%90%E5%91%98%E5%8F%98%E9%87%8F"><span class="toc-number">5.1.</span> <span class="toc-text">1.static 成员变量</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-static-%E6%88%90%E5%91%98%E6%96%B9%E6%B3%95"><span class="toc-number">5.2.</span> <span class="toc-text">2.static 成员方法</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-static-%E4%BB%A3%E7%A0%81%E5%9D%97"><span class="toc-number">5.3.</span> <span class="toc-text">3.static 代码块</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4-static-%E5%86%85%E9%83%A8%E7%B1%BB"><span class="toc-number">5.4.</span> <span class="toc-text">4.static 内部类</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#DeepinCopy-%E6%B7%B1%E6%8B%B7%E8%B4%9D"><span class="toc-number">6.</span> <span class="toc-text">DeepinCopy 深拷贝</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Sql-%E4%B8%AD-limit-%E4%B8%8E-offset%E8%BF%9E%E7%94%A8%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="toc-number">7.</span> <span class="toc-text">Sql 中 limit 与 offset连用的区别</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Java-%E5%AF%B9%E8%B1%A1%E4%B8%8E-JSON-%E6%95%B0%E6%8D%AE%E7%9A%84%E4%BA%92%E7%9B%B8%E8%BD%AC%E6%8D%A2"><span class="toc-number">8.</span> <span class="toc-text">Java 对象与 JSON 数据的互相转换</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%B0%86-Java-%E5%AF%B9%E8%B1%A1%E8%BD%AC%E6%8D%A2%E4%B8%BA%E5%AD%97%E7%AC%A6%E4%B8%B2-%E2%80%93-%E5%BA%8F%E5%88%97%E5%8C%96"><span class="toc-number">8.1.</span> <span class="toc-text">将 Java 对象转换为字符串 – (序列化)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%B0%86-JSON-%E6%A0%BC%E5%BC%8F%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%A7%A3%E6%9E%90%E4%B8%BA-Java-%E5%AF%B9%E8%B1%A1-%E2%80%93-%E5%8F%8D%E5%BA%8F%E5%88%97%E5%8C%96"><span class="toc-number">8.2.</span> <span class="toc-text">将 JSON 格式字符串解析为 Java 对象 – (反序列化)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%B0%86-Json-%E8%BD%AC%E6%8D%A2%E5%A4%8D%E6%9D%82%E7%9A%84-Bean-%E5%AF%B9%E8%B1%A1"><span class="toc-number">8.3.</span> <span class="toc-text">将 Json 转换复杂的 Bean 对象</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Gson-%E5%92%8C-Fastjson-%E5%8C%BA%E5%88%AB"><span class="toc-number">9.</span> <span class="toc-text">Gson 和 Fastjson 区别</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#Bean-%E8%BD%AC%E6%8D%A2-Json%EF%BC%9AtoJson"><span class="toc-number">9.1.</span> <span class="toc-text">Bean 转换 Json：toJson</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Json-%E8%BD%AC%E6%8D%A2-Bean%EF%BC%9AfromJson"><span class="toc-number">9.2.</span> <span class="toc-text">Json 转换 Bean：fromJson</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Json-%E8%BD%AC%E6%8D%A2%E5%A4%8D%E6%9D%82%E7%9A%84-Bean"><span class="toc-number">9.3.</span> <span class="toc-text">Json 转换复杂的 Bean</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Git%E5%BF%BD%E7%95%A5%E6%96%87%E4%BB%B6-gitignore"><span class="toc-number">10.</span> <span class="toc-text">Git忽略文件.gitignore</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%B8%B8%E7%94%A8%E5%8C%B9%E9%85%8D%E7%A4%BA%E4%BE%8B"><span class="toc-number">10.1.</span> <span class="toc-text">常用匹配示例</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Java-%E9%A1%B9%E7%9B%AE%E4%B8%AD%E5%B8%B8%E7%94%A8%E7%9A%84-gitignore-%E6%96%87%E4%BB%B6"><span class="toc-number">10.2.</span> <span class="toc-text">Java 项目中常用的 .gitignore 文件</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/47231/" title="POI读取Excel问题">POI读取Excel问题</a><time datetime="2023-04-11T01:00:00.000Z" title="发表于 2023-04-11 09:00:00">2023-04-11</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/8422/" title="Excel大文件的上传">Excel大文件的上传</a><time datetime="2023-04-10T01:00:00.000Z" title="发表于 2023-04-10 09:00:00">2023-04-10</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/55119/" title="每日一面--Files工具类">每日一面--Files工具类</a><time datetime="2023-01-01T01:00:00.000Z" title="发表于 2023-01-01 09:00:00">2023-01-01</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/34600/" title="面试一下--JUC入门">面试一下--JUC入门</a><time datetime="2022-09-10T01:00:00.000Z" title="发表于 2022-09-10 09:00:00">2022-09-10</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/16284/" title="每日一面--字符流和字节流">每日一面--字符流和字节流</a><time datetime="2022-07-01T01:00:00.000Z" title="发表于 2022-07-01 09:00:00">2022-07-01</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('https://gcore.jsdelivr.net/gh/PaulGeorge123/cloudimg@img/mig2023/background05.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By PaulGeorge</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></body></html>